package com.flute.framework.data.mysql;

import java.util.List;

import org.amino.ds.lockfree.LockFreeList;
import org.apache.commons.lang.StringUtils;

import com.flute.framework.data.constants.Constants;

public final class GroupBySQL {
	private List<String> groupByClauses;

	public void addGroupByClause(String groupByClause) {
		if (groupByClauses == null) {
			groupByClauses = new LockFreeList<String>();
		}
		if (!groupByClauses.contains(groupByClause)) {
			groupByClauses.add(groupByClause);
		}
	}

	public String toSQL() {
		if (groupByClauses == null || groupByClauses.isEmpty()) {
			return Constants.EMPTY;
		}
		return Constants.GROUP_BY + StringUtils.join(groupByClauses, ",");
	}
}
